<?php

namespace App\Cost;

class HourStageCost extends AbstractCost
{
    /**
     * @var int 包段小时数
     */
    public int $stageHours = 0;

    /**
     * @var int 包段价格
     */
    public int $perStagePrice = 0;

    protected function getCost(string $startTime, string $endTime): Price
    {
        //分钟数
        $minutes = (int)((strtotime($endTime) - strtotime($startTime)) / 60);
        //包段分钟数
        $stageMinutes = $this->stageHours * 60;
        //超时分钟数
        $exceedMinutes = $minutes - $stageMinutes;

        $basePrice = $this->perStagePrice;
        //没有超时，直接返回
        if ($exceedMinutes <= 0)
            return new Price($basePrice);

        $exceedFee = $this->getExceedFee($exceedMinutes);
        $exceedMessage = $this->getExceedMessage();

        return new Price($basePrice, $exceedMinutes, $exceedFee, $exceedMessage);
    }

    protected function getPricePerMinutes(): float
    {
        return ($this->perStagePrice / $this->stageHours / 60);
    }

    public function getPerMinutesPrice(): float|null
    {
        return null;
    }
}
